package com.linq.cool.beauty.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.linq.cool.beauty.domain.BeautyTopUp;
import com.linq.cool.beauty.dto.BeautyTopUpQueryDTO;
import com.linq.cool.beauty.dto.BeautyTopUpSelfQueryDTO;
import com.linq.cool.beauty.service.BeautyTopUpService;
import com.linq.cool.common.core.domain.BaseController;
import com.linq.cool.common.core.domain.PageVO;
import com.linq.cool.common.core.domain.Result;
import com.linq.cool.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: yqlin
 * @Date: 2021/2/3 00:17
 * @Description:
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("topUp")
public class BeautyTopUpController extends BaseController {
    @Autowired
    private BeautyTopUpService beautyTopUpService;

    @PreAuthorize(hasPerm = "beauty:topUp:list")
    @GetMapping("list")
    public Result<?> list(BeautyTopUpQueryDTO dto) {
        IPage<BeautyTopUp> page = beautyTopUpService.listByPage(dto.getPage(), dto);
        return Result.ok(new PageVO().setTotal(page.getTotal()).setRecords(page.getRecords()));
    }

    /**
     * 根据客户id查询所有充值记录
     *
     * @return
     */
    @GetMapping("listByMemberId")
    public Result<?> listByMemberId(BeautyTopUpSelfQueryDTO dto) {
        IPage<BeautyTopUp> page = beautyTopUpService.listBySelfPage(dto.getPage(), dto);
        return Result.ok(new PageVO().setTotal(page.getTotal()).setRecords(page.getRecords()));
    }

    /**
     * 根据充值订单id查询充值记录
     *
     * @param orderId
     *
     * @return
     */
    @GetMapping(value = "{orderId}")
    public Result<?> getInfo(@PathVariable("orderId") String orderId) {
        return Result.ok(beautyTopUpService.getById(orderId));
    }
}
